package com.xbongbong.saas.script.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasAppEntity;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.PaasMenuEntity;
import com.xbongbong.paas.domain.entity.PaasProcessNodeTaskEntity;
import com.xbongbong.paas.domain.entity.PaasProcessTaskEntity;
import com.xbongbong.paas.domain.entity.PaasProcessTemplateEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasProcessNodeTaskEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasProcessTemplateEntityExt;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LimitChooseRangePoJo;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.paas.help.menu.InitCrmMenuHelp;
import com.xbongbong.paas.help.menu.InitMenuHelp;
import com.xbongbong.paas.help.menu.InitProductMenuHelp;
import com.xbongbong.paas.help.menu.InitWorkOrderHelp;
import com.xbongbong.paas.model.PaasAppModel;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.model.PaasProcessNodeTaskModel;
import com.xbongbong.paas.model.PaasProcessTaskModel;
import com.xbongbong.paas.model.PaasProcessTemplateModel;
import com.xbongbong.paas.pojo.dto.FormAddDTO;
import com.xbongbong.paas.pojo.dto.FormEntityAddDTO;
import com.xbongbong.paas.pojo.dto.FormEntityUpdateDTO;
import com.xbongbong.paas.pojo.dto.FormExplainAddDTO;
import com.xbongbong.paas.pojo.dto.FormGetDTO;
import com.xbongbong.paas.pojo.dto.FormUpdateDTO;
import com.xbongbong.paas.pojo.vo.FormAddVO;
import com.xbongbong.paas.pojo.vo.FormEntityGetVO;
import com.xbongbong.paas.pojo.vo.FormExplainAddVO;
import com.xbongbong.paas.pojo.vo.FormGetVO;
import com.xbongbong.paas.service.PaasFormExplainService;
import com.xbongbong.paas.service.PaasFormService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.errorcodes.TemplateErrorCodeEnum;
import com.xbongbong.pro.enums.menu.enums.CRMMenuEnum;
import com.xbongbong.pro.enums.menu.enums.FundManagementMenuEnum;
import com.xbongbong.pro.enums.menu.enums.JXCMenuEnum;
import com.xbongbong.pro.enums.menu.enums.ProductMenuEnum;
import com.xbongbong.pro.enums.menu.enums.SystemAppMenuEnum;
import com.xbongbong.pro.form.pojo.dto.FormAddBatchDTO;
import com.xbongbong.pro.form.pojo.vo.FormAddBatchVO;
import com.xbongbong.pro.menu.pojo.dto.MenuInitDTO;
import com.xbongbong.pro.menu.pojo.vo.MenuFormAddBatchVO;
import com.xbongbong.pro.script.pojo.dto.AllScriptDTO;
import com.xbongbong.pro.script.pojo.dto.ScriptDTO;
import com.xbongbong.pro.script.pojo.vo.ScriptVO;
import com.xbongbong.saas.base.EnumBase;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.ParameterConstant;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.domain.entity.WorkOrderExplainEntity;
import com.xbongbong.saas.domain.entity.WorkOrderFormEntity;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.AllFieldEnum;
import com.xbongbong.saas.enums.business.AssembleEnum;
import com.xbongbong.saas.enums.business.BadDebtEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import com.xbongbong.saas.enums.business.CompetitorAnalysisEnum;
import com.xbongbong.saas.enums.business.CompetitorEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.CustomerCommunicateEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.InstockEnum;
import com.xbongbong.saas.enums.business.InventoryEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.business.MarketingActivityManagementEnum;
import com.xbongbong.saas.enums.business.OriStockEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.PurchaseInstockEnum;
import com.xbongbong.saas.enums.business.PushNotifyEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.RedPaymentSheetEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.StockProductEnum;
import com.xbongbong.saas.enums.business.SupplierCommunicateEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.business.TransferEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.business.WorkOrderEnum;
import com.xbongbong.saas.enums.business.WorkReportDailyEnum;
import com.xbongbong.saas.enums.business.WorkReportMonthlyEnum;
import com.xbongbong.saas.enums.business.WorkReportWeeklyEnum;
import com.xbongbong.saas.model.WorkOrderExplainModel;
import com.xbongbong.saas.model.WorkOrderFormModel;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.saas.script.service.InitExplainsService;
import com.xbongbong.saas.script.tempenum.TempAllFieldEnum;
import com.xbongbong.saas.script.tempenum.TempAssembleEnum;
import com.xbongbong.saas.script.tempenum.TempBadDebtEnum;
import com.xbongbong.saas.script.tempenum.TempBomBillEnum;
import com.xbongbong.saas.script.tempenum.TempClueEnum;
import com.xbongbong.saas.script.tempenum.TempCommunicatePlanEnum;
import com.xbongbong.saas.script.tempenum.TempCompetitorAnalysisEnum;
import com.xbongbong.saas.script.tempenum.TempCompetitorEnum;
import com.xbongbong.saas.script.tempenum.TempContactEnum;
import com.xbongbong.saas.script.tempenum.TempContractEnum;
import com.xbongbong.saas.script.tempenum.TempCustomerCommunicateEnum;
import com.xbongbong.saas.script.tempenum.TempCustomerManagementEnum;
import com.xbongbong.saas.script.tempenum.TempInstockEnum;
import com.xbongbong.saas.script.tempenum.TempInventoryEnum;
import com.xbongbong.saas.script.tempenum.TempInvoiceEnum;
import com.xbongbong.saas.script.tempenum.TempMarketActivityEnum;
import com.xbongbong.saas.script.tempenum.TempMarketingActivityManagementEnum;
import com.xbongbong.saas.script.tempenum.TempOriStockEnum;
import com.xbongbong.saas.script.tempenum.TempOutstockEnum;
import com.xbongbong.saas.script.tempenum.TempPayPlanEnum;
import com.xbongbong.saas.script.tempenum.TempPaySheetEnum;
import com.xbongbong.saas.script.tempenum.TempPaymentEnum;
import com.xbongbong.saas.script.tempenum.TempPaymentSheetEnum;
import com.xbongbong.saas.script.tempenum.TempProductEnum;
import com.xbongbong.saas.script.tempenum.TempProductionOrderEnum;
import com.xbongbong.saas.script.tempenum.TempPurchaseEnum;
import com.xbongbong.saas.script.tempenum.TempPurchaseInstockEnum;
import com.xbongbong.saas.script.tempenum.TempPushNotifyEnum;
import com.xbongbong.saas.script.tempenum.TempQuotationEnum;
import com.xbongbong.saas.script.tempenum.TempRedPaymentSheetEnum;
import com.xbongbong.saas.script.tempenum.TempRefundEnum;
import com.xbongbong.saas.script.tempenum.TempReturnedPurchaseEnum;
import com.xbongbong.saas.script.tempenum.TempSalesOpportunityEnum;
import com.xbongbong.saas.script.tempenum.TempStockProductEnum;
import com.xbongbong.saas.script.tempenum.TempSupplierCommunicateEnum;
import com.xbongbong.saas.script.tempenum.TempSupplierContactEnum;
import com.xbongbong.saas.script.tempenum.TempSupplierEnum;
import com.xbongbong.saas.script.tempenum.TempTransferEnum;
import com.xbongbong.saas.script.tempenum.TempWarehouseEnum;
import com.xbongbong.saas.script.tempenum.TempWorkOrderEnum;
import com.xbongbong.saas.script.tempenum.TempWorkReportDailyEnum;
import com.xbongbong.saas.script.tempenum.TempWorkReportMonthlyEnum;
import com.xbongbong.saas.script.tempenum.TempWorkReportWeeklyEnum;
import com.xbongbong.sys.domain.entity.ProPermissionEntity;
import com.xbongbong.sys.model.ProPermissionModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/17 14:43
 * @since v1.0
 */
@Service("InitExplainsService")
public class InitExplainsServiceImpl implements InitExplainsService {

    private static final Logger LOG = LoggerFactory.getLogger(InitExplainsServiceImpl.class);

    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private PaasMenuModel paasMenuModel;
    @Resource
    private PaasFormService paasFormService;
    @Resource
    private PaasFormExplainService paasFormExplainService;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private InitWorkOrderHelp initWorkOrderHelp;
    @Resource
    private InitMenuHelp initMenuHelp;
    @Resource
    private WorkOrderExplainModel workOrderExplainModel;
    @Resource
    private InitCrmMenuHelp initCrmMenuHelp;
    @Resource
    private WorkOrderFormModel workOrderFormModel;
    @Resource
    private PaasProcessTemplateModel paasProcessTemplateModel;
    @Resource
    private PaasProcessTaskModel paasProcessTaskModel;
    @Resource
    private PaasProcessNodeTaskModel paasProcessNodeTaskModel;
    @Resource
    private ProPermissionModel proPermissionModel;
    @Resource
    private PaasAppModel paasAppModel;
    @Resource
    private InitProductMenuHelp initProductMenuHelp;


    /**
     * 初始化客户
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initCustomer(ScriptDTO scriptDTO) throws XbbException {
        List<TempCustomerManagementEnum> allEnum = TempCustomerManagementEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("客户业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempCustomerManagementEnum customerEnum : allEnum) {
            CustomerManagementEnum anEnum = customerEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<CustomerManagementEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempCustomerManagementEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(customerEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(customerEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initCustomer=================================");
        return scriptVO;
    }

    private void commonFiledInit(FieldAttrEntity fieldAttrEntity) {
        Integer fieldType = fieldAttrEntity.getFieldType();
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(fieldType);
        if (Objects.isNull(fieldTypeEnum)){
            return;
        }
        switch (fieldTypeEnum){
            case NUM:
                fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo());
                break;
            case OWNERID:
            case COUSERID:
            case USER:
            case USER_GROUP:
                fieldAttrEntity.getDefaultAttr().setDefaultList(new ArrayList<>());
                break;
            case DEPT:
            case DEPT_GROUP:
                fieldAttrEntity.getDefaultAttr().setDefaultList(new ArrayList<>());
                fieldAttrEntity.setLimitChooseRange(new LimitChooseRangePoJo());
                break;
        }
    }

    /**
     * 初始化联系人
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initContact(ScriptDTO scriptDTO) throws XbbException {
        List<TempContactEnum> allEnum = TempContactEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("联系人业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempContactEnum contactEnum : allEnum) {
            ContactEnum anEnum = contactEnum.getAnEnum();
//
            // 包装业务枚举类
            EnumBase<ContactEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempContactEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(contactEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(contactEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.CONTACT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initContact=================================");
        return scriptVO;
    }

    /**
     * 初始化合同
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/19 17:57
     */
    @Override
    public ScriptVO initContract(ScriptDTO scriptDTO) throws XbbException {
        List<TempContractEnum> allEnum = TempContractEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("合同业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempContractEnum contractEnum : allEnum) {
            ContractEnum anEnum = contractEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<ContractEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempContractEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(contractEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(contractEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.CONTRACT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initContract=================================");
        return scriptVO;
    }

    /**
     * Description: 初始化销售机会
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-01-17 20:27
     */
    @Override
    public ScriptVO initOpportunity(ScriptDTO scriptDTO) throws XbbException {
        List<TempSalesOpportunityEnum> allEnum = TempSalesOpportunityEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("销售机会业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempSalesOpportunityEnum opportunityEnum : allEnum) {
            SalesOpportunityEnum anEnum = opportunityEnum.getAnEnum();

            // 包装业务枚举类
            EnumBase<SalesOpportunityEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempSalesOpportunityEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(opportunityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(opportunityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initOpportunity=================================");
        return scriptVO;
    }

    /**
     * 初始化访客计划
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initCommunicatePlan(ScriptDTO scriptDTO) throws XbbException {
        List<TempCommunicatePlanEnum> allEnum = TempCommunicatePlanEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("访客计划业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempCommunicatePlanEnum communicatePlanEnum : allEnum) {
            CommunicatePlanEnum anEnum = communicatePlanEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<CommunicatePlanEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempCommunicatePlanEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(communicatePlanEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(communicatePlanEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initCommunicatePlan=================================");
        return scriptVO;
    }

    /**
     * 初始化BOM清单
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initBomBill(ScriptDTO scriptDTO) throws XbbException {
        List<TempBomBillEnum> allEnum = TempBomBillEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("BOM清单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempBomBillEnum bomBillEnum : allEnum) {
            BomBillEnum anEnum = bomBillEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<BomBillEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempBomBillEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(bomBillEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(bomBillEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.BOM_BILL.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initBomBillEnum=================================");
        return scriptVO;
    }

    /**
     * 初始化客户跟进记录
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initCustomerCommunicate(ScriptDTO scriptDTO) throws XbbException {
        List<TempCustomerCommunicateEnum> allEnum = TempCustomerCommunicateEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("客户跟进记录业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempCustomerCommunicateEnum customerCommunicateEnum : allEnum) {
            CustomerCommunicateEnum anEnum = customerCommunicateEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<CustomerCommunicateEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempCustomerCommunicateEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(customerCommunicateEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(customerCommunicateEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.CUSTOMER_COMMUNICATE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initCustomerCommunicate=================================");
        return scriptVO;
    }

    /**
     * 初始化供应商跟进记录
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initSupplierCommunicate(ScriptDTO scriptDTO) throws XbbException {
        List<TempSupplierCommunicateEnum> allEnum = TempSupplierCommunicateEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("供应商跟进记录业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempSupplierCommunicateEnum supplierCommunicateEnum : allEnum) {
            SupplierCommunicateEnum anEnum = supplierCommunicateEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<SupplierCommunicateEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempSupplierCommunicateEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(supplierCommunicateEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(supplierCommunicateEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.SUPPLIER_COMMUNICATE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initSupplierCommunicate=================================");
        return scriptVO;
    }

    /**
     * 初始化工作报告(日报)
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initWorkReportDaily(ScriptDTO scriptDTO) throws XbbException {
        List<TempWorkReportDailyEnum> allEnum = TempWorkReportDailyEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("日报业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempWorkReportDailyEnum workReportDailyEnum : allEnum) {
            WorkReportDailyEnum anEnum = workReportDailyEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<WorkReportDailyEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempWorkReportDailyEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(workReportDailyEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(workReportDailyEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.WORKREPORT_DAILY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initWorkReportDaily=================================");
        return scriptVO;
    }


    /**
     * 初始化工作报告(周报)
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initWorkReportWeekly(ScriptDTO scriptDTO) throws XbbException {
        List<TempWorkReportWeeklyEnum> allEnum = TempWorkReportWeeklyEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("周报业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempWorkReportWeeklyEnum workReportWeeklyEnum : allEnum) {
            WorkReportWeeklyEnum anEnum = workReportWeeklyEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<WorkReportWeeklyEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempWorkReportWeeklyEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(workReportWeeklyEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(workReportWeeklyEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.WORKREPORT_WEEKLY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initWorkReportWeekly=================================");
        return scriptVO;
    }

    /**
     * 初始化工作报告(月报)
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initWorkReportMonthly(ScriptDTO scriptDTO) throws XbbException {
        List<TempWorkReportMonthlyEnum> allEnum = TempWorkReportMonthlyEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("月报业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempWorkReportMonthlyEnum workReportMonthlyEnum : allEnum) {
            WorkReportMonthlyEnum anEnum = workReportMonthlyEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<WorkReportMonthlyEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempWorkReportMonthlyEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(workReportMonthlyEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(workReportMonthlyEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }

        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.WORKREPORT_MONTHLY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initWorkReportMonthly=================================");
        return scriptVO;
    }

    /**
     * 初始化回款
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initPayment(ScriptDTO scriptDTO) throws XbbException {
        List<TempPaymentEnum> allEnum = TempPaymentEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("回款业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPaymentEnum paymentEnum : allEnum) {
            PaymentEnum anEnum = paymentEnum.getAnEnum();

            // 包装业务枚举类
            EnumBase<PaymentEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPaymentEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(paymentEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                if ( fieldAttrEntity.getAttr().equals(PaymentEnum.STATUS.getAttr()) ){
                    fieldAttrEntity.setItemBanDefault(BasicConstant.ONE);
                }
                fieldAttrEntity.setDefaultName(paymentEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PAYMENT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPayment=================================");
        return scriptVO;

    }

    /**
     * 初始化回款单
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initPaymentSheet(ScriptDTO scriptDTO) throws XbbException {
        List<TempPaymentSheetEnum> allEnum = TempPaymentSheetEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("回款单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPaymentSheetEnum paymentSheetEnum : allEnum) {
            PaymentSheetEnum anEnum = paymentSheetEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<PaymentSheetEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPaymentSheetEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(paymentSheetEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(paymentSheetEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PAYMENT_SHEET.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPaymentSheet=================================");
        return scriptVO;
    }

    /**
     * 初始化发票
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initInvoice(ScriptDTO scriptDTO) throws XbbException {
        List<TempInvoiceEnum> allEnum = TempInvoiceEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("发票业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        } else {
            List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
            List<String> enumAttrs = null;
            for (TempInvoiceEnum invoiceEnum : allEnum) {
                InvoiceEnum anEnum = invoiceEnum.getAnEnum();
                // 包装业务枚举类
                EnumBase<InvoiceEnum> enumBase = new EnumBase<>(anEnum);
                Class<?> clazz = enumBase.t.getClass();
                if (enumAttrs == null) {
                    // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                    enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
                }
                // 初始化字段解释
                FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
                if (fieldAttrEntity != null) {
                    String saasAttr = fieldAttrEntity.getSaasAttr();
                    String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                    String methodName = "init" + attr;
                    try {
                        commonFiledInit(fieldAttrEntity);
                        Method method = TempInvoiceEnum.class.getMethod(methodName, FieldAttrEntity.class);
                        method.invoke(invoiceEnum, fieldAttrEntity);
                    } catch (NoSuchMethodException e) {
                        // 没有对应字段的初始化方法

                    } catch (Exception e) {
                        LOG.error(e.getMessage());
                    }
                    fieldAttrEntity.setDefaultName(invoiceEnum.getAnEnum().getAttrName());
                    fieldAttrEntityList.add(fieldAttrEntity);
                }
            }

            ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.INVOICE.getCode(), fieldAttrEntityList);
            LOG.info("=========================模板数据刷成功了initInvoice=================================");
            return scriptVO;
        }
    }

    /**
     * 初始化付款计划
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initPayPlan(ScriptDTO scriptDTO) throws XbbException {
        List<TempPayPlanEnum> allEnum = TempPayPlanEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("付款计划业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        } else {
            List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
            List<String> enumAttrs = null;
            for (TempPayPlanEnum payPlanEnum : allEnum) {
                PayPlanEnum anEnum = payPlanEnum.getAnEnum();
                // 包装业务枚举类
                EnumBase<PayPlanEnum> enumBase = new EnumBase<>(anEnum);
                Class<?> clazz = enumBase.t.getClass();
                if (enumAttrs == null) {
                    // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                    enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
                }
                // 初始化字段解释
                FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
                if (fieldAttrEntity != null) {
                    String saasAttr = fieldAttrEntity.getSaasAttr();
                    String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                    String methodName = "init" + attr;
                    try {
                        commonFiledInit(fieldAttrEntity);
                        Method method = TempPayPlanEnum.class.getMethod(methodName, FieldAttrEntity.class);
                        method.invoke(payPlanEnum, fieldAttrEntity);
                    } catch (NoSuchMethodException e) {
                        // 没有对应字段的初始化方法

                    } catch (Exception e) {
                        LOG.error(e.getMessage());
                    }
                    fieldAttrEntity.setDefaultName(payPlanEnum.getAnEnum().getAttrName());
                    fieldAttrEntityList.add(fieldAttrEntity);
                }
            }

            ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PAY_PLAN.getCode(), fieldAttrEntityList);
            LOG.info("=========================模板数据刷成功了initPayPlan=================================");
            return scriptVO;
        }
    }

    /**
     * 初始化生产单
     *
     * @param scriptDTO 刷脚本入参
     * @author feng.zheng
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initProductionOrder(ScriptDTO scriptDTO) throws XbbException {
        List<TempProductionOrderEnum> allEnum = TempProductionOrderEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("生产单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        } else {
            List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
            List<String> enumAttrs = null;
            for (TempProductionOrderEnum productOrderEnum : allEnum) {
                ProductionOrderEnum anEnum = productOrderEnum.getAnEnum();
                // 包装业务枚举类
                EnumBase<ProductionOrderEnum> enumBase = new EnumBase<>(anEnum);
                Class<?> clazz = enumBase.t.getClass();
                if (enumAttrs == null) {
                    // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                    enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
                }
                // 初始化字段解释
                FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
                if (fieldAttrEntity != null) {
                    String saasAttr = fieldAttrEntity.getSaasAttr();
                    String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                    String methodName = "init" + attr;
                    try {
                        commonFiledInit(fieldAttrEntity);
                        Method method = TempProductionOrderEnum.class.getMethod(methodName, FieldAttrEntity.class);
                        method.invoke(productOrderEnum, fieldAttrEntity);
                    } catch (NoSuchMethodException e) {
                        // 没有对应字段的初始化方法

                    } catch (Exception e) {
                        LOG.error(e.getMessage());
                    }
                    fieldAttrEntity.setDefaultName(productOrderEnum.getAnEnum().getAttrName());
                    fieldAttrEntityList.add(fieldAttrEntity);
                }
            }

            ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), fieldAttrEntityList);
            LOG.info("=========================模板数据刷成功了initProductOrder=================================");
            return scriptVO;
        }

    }


    /**
     * 初始化供应商
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initSupplier(ScriptDTO scriptDTO) throws XbbException {
        List<TempSupplierEnum> allEnum = TempSupplierEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempSupplierEnum supplierEnum : allEnum) {
            SupplierEnum anEnum = supplierEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<SupplierEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempSupplierEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(supplierEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(supplierEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.SUPPLIER.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initSupplier=================================");
        return scriptVO;
    }

    /**
     * 初始化供应商联系人
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initSupplierContact(ScriptDTO scriptDTO) throws XbbException {
        List<TempSupplierContactEnum> allEnum = TempSupplierContactEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempSupplierContactEnum supplierContactEnum : allEnum) {
            SupplierContactEnum anEnum = supplierContactEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<SupplierContactEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempSupplierContactEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(supplierContactEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(supplierContactEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.SUPPLIER_CONTACT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initSupplierContact=================================");
        return scriptVO;
    }

    /**
     * 初始化采购合同
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initPurchase(ScriptDTO scriptDTO) throws XbbException {
        List<TempPurchaseEnum> allEnum = TempPurchaseEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPurchaseEnum purchaseEnum : allEnum) {
            PurchaseEnum anEnum = purchaseEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<PurchaseEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPurchaseEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(purchaseEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(purchaseEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PURCHASE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPurchase=================================");
        return scriptVO;
    }

    /**
     * 初始化报价单
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException
     * @author long.rao
     * @date 2019-08-12 16:48
     */
    @Override
    public ScriptVO initQuotation(ScriptDTO scriptDTO) throws XbbException {
        List<TempQuotationEnum> allEnum = TempQuotationEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempQuotationEnum quotationEnum : allEnum) {
            QuotationEnum anEnum = quotationEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<QuotationEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempQuotationEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(quotationEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(quotationEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.QUOTATION.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initQuotation=================================");
        return scriptVO;
    }

    /**
     * 初始化线索
     *
     * @param scriptDTO 刷脚本入参
     * @throws XbbException
     * @author long.rao
     * @date 20120-11-4 16:48
     */
    @Override
    public ScriptVO initClue(ScriptDTO scriptDTO) throws XbbException {
        List<TempClueEnum> allEnum = TempClueEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempClueEnum clueEnum : allEnum) {
            ClueEnum anEnum = clueEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<ClueEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempClueEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(clueEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(clueEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.CLUE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initClue=================================");
        return scriptVO;
    }

    /**
     * 初始化采购退货单
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/17
     */
    @Override
    public ScriptVO initReturnedPurchase(ScriptDTO scriptDTO) throws XbbException {
        List<TempReturnedPurchaseEnum> allEnum = TempReturnedPurchaseEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempReturnedPurchaseEnum returnedPurchaseEnum : allEnum) {
            ReturnedPurchaseEnum anEnum = returnedPurchaseEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<ReturnedPurchaseEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempReturnedPurchaseEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(returnedPurchaseEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(returnedPurchaseEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.RETURNED_PURCHASE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initReturnedPurchase=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initInventory(ScriptDTO scriptDTO) throws XbbException {
        List<TempInventoryEnum> allEnum = TempInventoryEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("盘点单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempInventoryEnum entityEnum : allEnum) {
            InventoryEnum anEnum = entityEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<InventoryEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempInventoryEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(entityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(entityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.INVENTORY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initInventory=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initPurchaseInstock(ScriptDTO scriptDTO) throws XbbException {
        List<TempPurchaseInstockEnum> allEnum = TempPurchaseInstockEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("采购入库单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPurchaseInstockEnum entityEnum : allEnum) {
            PurchaseInstockEnum anEnum = entityEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<PurchaseInstockEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPurchaseInstockEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(entityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(entityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PURCHASE_INSTOCK.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPurchaseInstock=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initInstock(ScriptDTO scriptDTO) throws XbbException {
        List<TempInstockEnum> allEnum = TempInstockEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("入库单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempInstockEnum entityEnum : allEnum) {
            InstockEnum anEnum = entityEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<InstockEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempInstockEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(entityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(entityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.INSTOCK.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initInstock=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initOutstock(ScriptDTO scriptDTO) throws XbbException {
        List<TempOutstockEnum> allEnum = TempOutstockEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("出库单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempOutstockEnum entityEnum : allEnum) {
            OutstockEnum anEnum = entityEnum.getAnEnum();

            // 包装业务枚举类
            EnumBase<OutstockEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempOutstockEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(entityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(entityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.OUTSTOCK.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initOutstock=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initProduct(ScriptDTO scriptDTO) throws XbbException {
        List<TempProductEnum> allEnum = TempProductEnum.getAllEnum();
        if (allEnum == null) {
            LOG.error("产品业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempProductEnum productEnum : allEnum) {
            ProductEnum anEnum = productEnum.getAnEnum();

            // 包装业务枚举类
            EnumBase<ProductEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempProductEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(productEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(productEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PRODUCT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initProduct=================================");
        return scriptVO;
    }

    /**
     * 初始化调拨单
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/19 17:08
     */
    @Override
    public ScriptVO initTransfer(ScriptDTO scriptDTO) throws XbbException {
        List<TempTransferEnum> allEnum = TempTransferEnum.getAllEnum();
        if (allEnum == null) {
            LOG.error("产品业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempTransferEnum transferEnum : allEnum) {
            TransferEnum anEnum = transferEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<TransferEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempTransferEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(transferEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(transferEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.TRANSFER.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initTransfer=================================");
        return scriptVO;
    }

    /**
     * 初始化装配单
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/19 17:59
     */
    @Override
    public ScriptVO initAssemble(ScriptDTO scriptDTO) throws XbbException {
        List<TempAssembleEnum> allEnum = TempAssembleEnum.getAllEnum();
        if (allEnum == null) {
            LOG.error("产品业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempAssembleEnum assembleEnum : allEnum) {
            AssembleEnum anEnum = assembleEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<AssembleEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempAssembleEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(assembleEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(assembleEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.ASSEMBLE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initAssemble=================================");
        return scriptVO;
    }

    /**
     * 初始化仓库
     *
     * @param scriptDTO 刷脚本入参
     * @author Jian.Wang
     * @date 2019/1/19 19:37
     */
    @Override
    public ScriptVO initWarehouse(ScriptDTO scriptDTO) throws XbbException {
        List<TempWarehouseEnum> allEnum = TempWarehouseEnum.getAllEnum();
        if (allEnum == null) {
            LOG.error("产品业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempWarehouseEnum warehouseEnum : allEnum) {
            WarehouseEnum anEnum = warehouseEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<WarehouseEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempWarehouseEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(warehouseEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(warehouseEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.WAREHOUSE.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initWarehouse=================================");
        return scriptVO;
    }

    /**
     * 初始化全部属性
     *
     * @param scriptDTO 刷脚本入参
     * @return ScriptVO 返回表单解释id
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/19 14:00
     */
    @Override
    public ScriptVO initAllField(ScriptDTO scriptDTO) throws XbbException {
        List<TempAllFieldEnum> allEnum = TempAllFieldEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("全部属性业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempAllFieldEnum allFieldEnum : allEnum) {
            AllFieldEnum anEnum = allFieldEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<AllFieldEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempAllFieldEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(allFieldEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.SYSTEM.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initAllField=================================");
        return scriptVO;
    }

    /**
     * 初始化付款单
     *
     * @param scriptDTO 刷脚本入参
     * @return ScriptVO 返回表单解释id
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/19 14:00
     */
    @Override
    public ScriptVO initPayPlanSheet(ScriptDTO scriptDTO) throws XbbException {
        List<TempPaySheetEnum> allEnum = TempPaySheetEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("付款单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPaySheetEnum paySheetEnum : allEnum) {
            PaySheetEnum anEnum = paySheetEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<PaySheetEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPaySheetEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(paySheetEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(paySheetEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PAY_SHEET.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPayPlanSheet=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initRedPaymentSheet(ScriptDTO scriptDTO) throws XbbException {
        List<TempRedPaymentSheetEnum> allEnum = TempRedPaymentSheetEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("红冲回款单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempRedPaymentSheetEnum paySheetEnum : allEnum) {
            RedPaymentSheetEnum anEnum = paySheetEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<RedPaymentSheetEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempRedPaymentSheetEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(paySheetEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(paySheetEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.RED_PAYMENT_SHEET.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initRedPaymentSheet=================================");
        return scriptVO;
    }

    /**
     * 初始化退货退款
     *
     * @param scriptDTO 刷脚本入参
     * @return ScriptVO 返回表单解释id
     * @throws XbbException 业务异常
     * @author feng.zheng
     * @date 2019/1/19 14:00
     */
    @Override
    public ScriptVO initRefund(ScriptDTO scriptDTO) throws XbbException {
        List<TempRefundEnum> allEnum = TempRefundEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("退货退款单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempRefundEnum refundEnum : allEnum) {
            RefundEnum anEnum = refundEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<RefundEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempRefundEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(refundEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(refundEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.REFUND.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initRefund=================================");
        return scriptVO;
    }

    /**
     * 初始化期初库存表单
     *
     * @param scriptDTO 刷脚本入参
     * @return ScriptVO 返回表单解释id
     * @throws XbbException 业务异常
     * @author caoyy
     * @date 2019/1/19 14:00
     */
    @Override
    public ScriptVO initWarehouseOriStock(ScriptDTO scriptDTO) throws XbbException{
        List<TempOriStockEnum> allEnum = TempOriStockEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("期初库存业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempOriStockEnum oriStockEnum : allEnum) {
            OriStockEnum anEnum = oriStockEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<OriStockEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempOriStockEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(oriStockEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(oriStockEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.ORI_STOCK.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initWarehouseOriStock=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initPushNotify(ScriptDTO scriptDTO) throws XbbException {
        List<TempPushNotifyEnum> allEnum = TempPushNotifyEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("跟进提醒业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempPushNotifyEnum pushNotifyEnum : allEnum) {
            PushNotifyEnum anEnum = pushNotifyEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<PushNotifyEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempPushNotifyEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(pushNotifyEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(pushNotifyEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.PUSH_NOTIFY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initPushNotify=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initBadDebt(ScriptDTO scriptDTO) throws XbbException {
        List<TempBadDebtEnum> allEnum = TempBadDebtEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("坏账回款单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempBadDebtEnum badDebtEnum : allEnum) {
            BadDebtEnum anEnum = badDebtEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<BadDebtEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempBadDebtEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(badDebtEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(badDebtEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }

        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.BAD_DEBT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initBadDebt=================================");
        return scriptVO;
    }

    /**
     * 初始化库存产品
     *
     * @param scriptDTO 入参
     * @return 回参
     * @throws XbbException 异常
     */
    @Override
    public ScriptVO initStockProduct(ScriptDTO scriptDTO) throws XbbException {
        List<TempStockProductEnum> allEnum = TempStockProductEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("库存产品业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempStockProductEnum stockProductEnum : allEnum) {
            StockProductEnum anEnum = stockProductEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<StockProductEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempStockProductEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(stockProductEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法

                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(stockProductEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.STOCK_PRODUCT.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initStockProduct=================================");
        return scriptVO;
    }

    /**
     * 插入表单返回表单id
     *
     * @param scriptDTO    脚本入参
     * @param businessType 业务类型
     * @return java.lang.Integer
     * @author feng.zheng
     * @date 2019/1/21 10:40
     */
    private Long insertForm(ScriptDTO scriptDTO, Integer businessType) throws XbbException {
        //获取菜单
        PaasMenuEntity paasMenuEntity = paasMenuModel.getByKey(scriptDTO.getMenuId(), scriptDTO.getCorpid());
        if (paasMenuEntity == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100028, MessageConstant.MENU_NOT_EXIST);
        }
        //如果该表单已经刷过，更新该表单解释

        PaasFormEntity paasFormEntity;
        try {
            paasFormEntity = paasFormModel.getByMenuId(scriptDTO.getMenuId(), scriptDTO.getCorpid());
        } catch (Exception e) {
            LOG.error("该菜单对应了多个表单", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001,"该菜单对应了多个表单");
        }
        if (paasFormEntity != null) {
            return paasFormEntity.getId();
        }
        //插入表单
        FormAddDTO formAddDTO = new FormAddDTO();
        BeanUtil.copyProperties(scriptDTO, formAddDTO);
        formAddDTO.setName(paasMenuEntity.getName());
        formAddDTO.setUserId(scriptDTO.getUserId());
        formAddDTO.setCorpid(scriptDTO.getCorpid());
        FormEntityAddDTO formEntityAddDTO = new FormEntityAddDTO();
        formEntityAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
        formEntityAddDTO.setBusinessType(businessType);
        formEntityAddDTO.setCustomTitle(initProductMenuHelp.getAppDefaultTitle(businessType));
        formEntityAddDTO.setLabels(initProductMenuHelp.getAppDefaultLabel(businessType));
        formAddDTO.setFormAttr(formEntityAddDTO);
        FormAddVO formAddVO = paasFormService.add(formAddDTO);
        if (Objects.isNull(formAddVO)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_ADD_FAILED);
        }
        Long formId;
        formId = formAddVO.getFormId();

        return formId;
    }

    /**
     * 插入表单及表单解释
     *
     * @param scriptDTO           脚本入参
     * @param businessType        业务类型
     * @param fieldAttrEntityList 解释实体
     * @return ScriptVO 返回表单解释id
     * @author feng.zheng
     * @date 2019/1/21 16:37
     */
    private ScriptVO insertFormExplain(ScriptDTO scriptDTO, Integer businessType, List<FieldAttrEntity> fieldAttrEntityList) throws XbbException {
        ScriptVO scriptVO = new ScriptVO();
        Integer isAddExplain = scriptDTO.getIsAddExplain();
        Long formId = scriptDTO.getFormId();
        // 向菜单插入解释
        if (isAddExplain == 1) {
            Boolean updateForm = true;
            // 插入表单，获取表单id。如果该公司下已经存在该表单，则返回该表单的 formId
            if (formId == null) {
                formId = insertForm(scriptDTO, businessType);
                updateForm = false;
            }
            // 获取表单解释是否已存在，存在则更新，不存在则插入
            PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByFormId(formId, scriptDTO.getCorpid());
            // 新增表单解释
            if (paasFormExplainEntity == null) {
                // 表单解释实体
                FormExplainAddDTO formExplainAddDTO = new FormExplainAddDTO();
                BeanUtil.copyProperties(scriptDTO, formExplainAddDTO);
                formExplainAddDTO.setFormId(formId);
                formExplainAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
                formExplainAddDTO.setBusinessType(businessType);
                formExplainAddDTO.setFormList(fieldAttrEntityList);
                FormExplainAddVO formExplainAddVO = paasFormExplainService.add(formExplainAddDTO);
                if (Objects.isNull(formExplainAddVO)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_ADD_FAILED);
                }
                scriptVO.setFormExplainId(formExplainAddVO.getFormExplainId());
            } else {
                // 更新表单解释
                BeanUtil.copyProperties(scriptDTO, paasFormExplainEntity);
                paasFormExplainEntity.setBusinessType(businessType);
                paasFormExplainEntity.setSaasMark(SaasMarkEnum.SAAS.getCode());
                paasFormExplainEntity.setExplains(JSONObject.toJSONString(fieldAttrEntityList));
                try {
                    paasFormExplainModel.update(paasFormExplainEntity);
                    scriptVO.setFormExplainId(paasFormExplainEntity.getId());
                } catch (Exception e) {
                    LOG.error("表单解释更新失败", e);
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
                }
            }
            if (updateForm) {
                FormGetDTO formGetDTO = new FormGetDTO();
                BeanUtil.copyProperties(scriptDTO, formGetDTO);
                formGetDTO.setBusinessType(businessType);
                FormGetVO formGetVO = paasFormService.get(formGetDTO);
                FormUpdateDTO formUpdateDTO = new FormUpdateDTO();
                BeanUtil.copyProperties(scriptDTO, formUpdateDTO);
                BeanUtil.copyProperties(formGetVO, formUpdateDTO);

                formUpdateDTO.setExplainList(fieldAttrEntityList);
                FormEntityGetVO formEntityGetVO = formGetVO.getFormAttr();
                FormEntityUpdateDTO formEntityUpdateDTO = new FormEntityUpdateDTO();
                BeanUtil.copyProperties(formEntityGetVO, formEntityUpdateDTO);
                formEntityUpdateDTO.setCustomTitle(initProductMenuHelp.getAppDefaultTitle(businessType));
                formEntityUpdateDTO.setLabels(initProductMenuHelp.getAppDefaultLabel(businessType));
                formUpdateDTO.setFormAttr(formEntityUpdateDTO);
                paasFormService.update(formUpdateDTO);
            }
        } else {
            PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByBusinessType(businessType,"0");
            if (paasFormExplainEntity == null){
                // 表单解释实体，插入corpid =0 数据
                FormExplainAddDTO formExplainAddDTO = new FormExplainAddDTO();
                BeanUtil.copyProperties(scriptDTO, formExplainAddDTO);
                formExplainAddDTO.setFormId((long) 0);
                formExplainAddDTO.setCorpid("0");
                // 暂时为paas标识，不然会取corpid为0的解释
                formExplainAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
                formExplainAddDTO.setBusinessType(businessType);
                formExplainAddDTO.setFormList(fieldAttrEntityList);
                FormExplainAddVO formExplainAddVO = paasFormExplainService.add(formExplainAddDTO);
                if (Objects.isNull(formExplainAddVO)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_EXPLAIN_ADD_FAILED);
                }
                scriptVO.setFormExplainId(formExplainAddVO.getFormExplainId());
            } else {
                // 更新表单解释
                BeanUtil.copyProperties(scriptDTO, paasFormExplainEntity);
                paasFormExplainEntity.setFormId(0L);
                paasFormExplainEntity.setBusinessType(businessType);
                paasFormExplainEntity.setSaasMark(SaasMarkEnum.SAAS.getCode());
                paasFormExplainEntity.setExplains(JSONObject.toJSONString(fieldAttrEntityList));
                try {
                    paasFormExplainModel.update(paasFormExplainEntity);
                    scriptVO.setFormExplainId(paasFormExplainEntity.getId());
                } catch (Exception e) {
                    LOG.error("表单解释更新失败", e);
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
                }
            }
        }
        return scriptVO;
    }

    @Override
    public ScriptVO initWorkOrder(ScriptDTO scriptDTO) throws XbbException {
        List<TempWorkOrderEnum> allEnum = TempWorkOrderEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("工单业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempWorkOrderEnum workOrderEnum : allEnum) {
            WorkOrderEnum anEnum = workOrderEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<WorkOrderEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    Method method = TempWorkOrderEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(workOrderEnum, fieldAttrEntity);
                    commonFiledInit(fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(workOrderEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
//        MenuInitDTO menuInitDTO = new MenuInitDTO();
//        BeanUtil.copyProperties(scriptDTO, menuInitDTO);
//        initWorkOrderHelp.initMenu(menuInitDTO);
        LOG.info("=========================模板数据刷成功了initWorkOrder=================================");
        ScriptVO scriptVO = insertWorkOrderFormExplain(scriptDTO, XbbRefTypeEnum.WORK_ORDER.getCode(), fieldAttrEntityList);
        return scriptVO;
    }

    private ScriptVO insertWorkOrderFormExplain(ScriptDTO scriptDTO, int code, List<FieldAttrEntity> fieldAttrEntityList) throws XbbException {
        ScriptVO scriptVO = new ScriptVO();
        Long formId = scriptDTO.getFormId();
        // 获取表单解释是否已存在，存在则更新，不存在则插入
        WorkOrderExplainEntity workOrderExplainEntity = workOrderExplainModel.getByFormId(formId, scriptDTO.getCorpid());
        // 更新表单解释
        BeanUtil.copyProperties(scriptDTO, workOrderExplainEntity);
        workOrderExplainEntity.setExplains(JSONObject.toJSONString(fieldAttrEntityList));
        try {
            workOrderExplainModel.update(workOrderExplainEntity);
            scriptVO.setFormExplainId(workOrderExplainEntity.getId());
        } catch (Exception e) {
            LOG.error("表单解释更新失败", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        return scriptVO;
    }


    @Override
    public ScriptVO initAll(AllScriptDTO allScriptDTO) throws XbbException {
        if (true){
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(),"有内鬼，终止交易");
        }
//        String corpid = allScriptDTO.getCorpid();
        List<String> corpidList = allScriptDTO.getCorpidList();
        for (String corpid : corpidList) {
            List<Integer> businessTypeList = allScriptDTO.getBusinessTypeList();

            for (Integer businessType : businessTypeList) {
                ScriptDTO scriptDTO = new ScriptDTO();
                scriptDTO.setCorpid(corpid);
                scriptDTO.setIsAddExplain(1);
                Map<String, Object> map = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                map.put("corpid", corpid);
                map.put("del", 0);
                if (Objects.equals(businessType, XbbRefTypeEnum.WORK_ORDER.getCode())) {
                    List<WorkOrderExplainEntity> workOrderExplainEntityList = workOrderExplainModel.findEntitys(map);
                    for (WorkOrderExplainEntity workOrderExplainEntity : workOrderExplainEntityList) {
                        PaasMenuEntity paasMenuEntity = paasMenuModel.getByAlias(XbbRefTypeEnum.WORK_ORDER.getAlias(),workOrderExplainEntity.getAppId(), corpid);
                        if (paasMenuEntity == null) {
                            MenuInitDTO menuInitDTO = new MenuInitDTO();
                            BeanUtil.copyProperties(allScriptDTO, menuInitDTO);
                            menuInitDTO.setCorpid(corpid);
                            menuInitDTO.setCompanyInit(1);
                            menuInitDTO.setAppId(workOrderExplainEntity.getAppId());
                            MenuFormAddBatchVO menuFormAddBatchVO = initWorkOrderHelp.formAddBatch(menuInitDTO);
                            //初始化工单表单
                            Long menuId = 0L;
                            for (PaasMenuEntity item : menuFormAddBatchVO.getMenuList()) {
                                if (Objects.equals(XbbRefTypeEnum.WORK_ORDER.getAlias(), item.getAlias())) {
                                    menuId = item.getId();
                                    break;
                                }
                            }
                            WorkOrderFormEntity paasFormEntity = new WorkOrderFormEntity();
                            paasFormEntity.setId(workOrderExplainEntity.getFormId());
                            paasFormEntity.setCorpid(corpid);
                            paasFormEntity.setMenuId(menuId);
                            workOrderFormModel.update(paasFormEntity);
                            workOrderExplainEntity.setMenuId(menuId);
                        } else {
                            Long menuId = paasMenuEntity.getId();
                            WorkOrderFormEntity paasFormEntity = new WorkOrderFormEntity();
                            paasFormEntity.setId(workOrderExplainEntity.getFormId());
                            paasFormEntity.setCorpid(corpid);
                            paasFormEntity.setMenuId(menuId);
                            workOrderFormModel.update(paasFormEntity);
                            WorkOrderExplainEntity workOrderExplainEntity1 = new WorkOrderExplainEntity();
                            workOrderExplainEntity1.setId(workOrderExplainEntity.getId());
                            workOrderExplainEntity1.setCorpid(corpid);
                            workOrderExplainEntity1.setMenuId(menuId);
                            workOrderExplainModel.update(workOrderExplainEntity1);
                            Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                            param.put("corpid", corpid);
                            param.put("formId", workOrderExplainEntity.getFormId());
                            param.put("businessType", XbbRefTypeEnum.WORK_ORDER.getCode());
                            param.put("del", 0);
                            List<PaasProcessTemplateEntityExt> templateEntities = paasProcessTemplateModel.list(param);
                            if (Objects.nonNull(templateEntities)) {
                                templateEntities.forEach(item->{
                                    PaasProcessTemplateEntity paasProcessTemplateEntity = new PaasProcessTemplateEntity();
                                    paasProcessTemplateEntity.setId(item.getId());
                                    paasProcessTemplateEntity.setMenuId(menuId);
                                    paasProcessTemplateEntity.setCorpid(corpid);
                                    paasProcessTemplateModel.update(paasProcessTemplateEntity);
                                });
                            }
                            param.clear();
                            param.put("corpid", corpid);
                            param.put("formId", workOrderExplainEntity.getFormId());
                            param.put("businessType", XbbRefTypeEnum.WORK_ORDER.getCode());
                            param.put("del", 0);
                            List<PaasProcessTaskEntity> processTaskList = paasProcessTaskModel.list(param);
                            if (Objects.nonNull(processTaskList)) {
                                for (PaasProcessTaskEntity item : processTaskList) {
                                    PaasProcessTaskEntity paasProcessTaskEntity = new PaasProcessTaskEntity();
                                    paasProcessTaskEntity.setId(item.getId());
                                    paasProcessTaskEntity.setMenuId(menuId);
                                    paasProcessTaskEntity.setCorpid(corpid);
                                    paasProcessTaskModel.update(paasProcessTaskEntity);
                                    param.put("taskId", item.getId());
                                    param.put("del", 0);
                                    List<PaasProcessNodeTaskEntityExt> processNodeTaskList = paasProcessNodeTaskModel.findEntitys(param);
                                    if (Objects.nonNull(processNodeTaskList)) {
                                        for (PaasProcessNodeTaskEntityExt nodeTask : processNodeTaskList) {
                                            PaasProcessNodeTaskEntity paasProcessNodeTaskEntityExt = new PaasProcessNodeTaskEntity();
                                            paasProcessNodeTaskEntityExt.setId(nodeTask.getId());
                                            paasProcessNodeTaskEntityExt.setMenuId(menuId);
                                            paasProcessNodeTaskEntityExt.setCorpid(corpid);
                                            paasProcessNodeTaskModel.update(paasProcessNodeTaskEntityExt);
                                        }
                                    }
                                }
                            }

                        }
                        scriptDTO.setAppId(workOrderExplainEntity.getAppId());
                        scriptDTO.setMenuId(workOrderExplainEntity.getMenuId());
                        scriptDTO.setFormId(workOrderExplainEntity.getFormId());
                        handOut(businessType, scriptDTO);
                    }
                } else {
                    map.put("businessType", businessType);
                    List<PaasFormEntityExt> paasFormEntityList = paasFormModel.list(map);
                    for (PaasFormEntityExt entityExt : paasFormEntityList) {
                        scriptDTO.setAppId(entityExt.getAppId());
                        scriptDTO.setMenuId(entityExt.getMenuId());
                        scriptDTO.setFormId(entityExt.getId());
                        handOut(businessType, scriptDTO);
                    }
                }
            }
        }
        return new ScriptVO();
    }

    @Override
    public BaseVO initPermission(BaseDTO baseDTO) throws XbbException {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("enable", 1);
        param.put(ParameterConstant.DEL, DelEnum.NORMAL.getDel());
        param.put("aliasLike","outstock");
        List<ProPermissionEntity> entitys = proPermissionModel.findEntitys(param);
        for (ProPermissionEntity proPermissionEntity : entitys) {
            String alias = proPermissionEntity.getAlias();
            char[] chars = alias.toCharArray();
            String aa = "";
            for (int i = 0; i < chars.length; i ++) {
                String newStr = String.valueOf(chars[i]).replaceAll("[A-Z]", "_" + chars[i]);
                aa = aa + newStr;
            }
            aa = aa.toUpperCase();
            System.out.println(aa + "(" + "\"" + proPermissionEntity.getAlias() + "\"" + StringConstant.COMMA + "\"" + proPermissionEntity.getFullName() + "\"" + ")" + ",");
        }
        return new BaseVO();
    }

    @Override
    public ScriptVO initQuickAndCommon(AllScriptDTO allScriptDTO) throws XbbException {
        try {

            for (String item : allScriptDTO.getCorpidList()) {
                MenuInitDTO menuInitDTO = new MenuInitDTO();
                BeanUtil.copyProperties(allScriptDTO, menuInitDTO);
                menuInitDTO.setCorpid(item);
                initProductMenuHelp.initQuickAndCommon(menuInitDTO);
            }
        }catch (Exception e) {

        }
        return new ScriptVO();
    }

    @Override
    public ScriptVO initBIProductAndPerformance(AllScriptDTO allScriptDTO) throws XbbException {
        try {
            for (String corpid : allScriptDTO.getCorpidList()) {
                Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                param.put(StringConstant.CORPID, corpid);
                param.put(StringConstant.DEL, DelEnum.NORMAL.getDel());
                List<String> aliasIn = new ArrayList<>();
                aliasIn.add(SystemAppMenuEnum.PRODUCT.getAlias());
                aliasIn.add(SystemAppMenuEnum.CRM.getAlias());
                param.put("aliasIn", aliasIn);
                param.put("columns", "corpid,alias,id");
                List<PaasAppEntity> appList = paasAppModel.findEntitys(param);
                if (Objects.isNull(appList)) {
                    continue;
                }
                //appList最大为2
                if(appList.size() > 2){
                    LOG.error("appList.size()" + appList.size());
                     throw  new XbbException(TemplateErrorCodeEnum.API_ERROR_350009);
                }
                List<FormEntityAddDTO> formList = new ArrayList<>();
                for (PaasAppEntity paasAppEntity : appList) {
                    if(SystemAppMenuEnum.PRODUCT.getAlias().equals(paasAppEntity.getAlias())){
                        initProductMenuHelp.setRefProductForm(paasAppEntity.getId(),formList,corpid,allScriptDTO.getUserId());
                    }else if(SystemAppMenuEnum.CRM.getAlias().equals(paasAppEntity.getAlias())){
                        initCrmMenuHelp.setContractPerformance(paasAppEntity.getId(),formList,corpid,allScriptDTO.getUserId());
                    }
                }
                FormAddBatchDTO formAddBatchDTO = new FormAddBatchDTO();
                formAddBatchDTO.setFormList(formList);
                BeanUtil.copyProperties(allScriptDTO,formAddBatchDTO);
                FormAddBatchVO formAddBatchVO = paasFormService.addBatch(formAddBatchDTO);
                if (Objects.isNull(formAddBatchVO)) {
                    throw new XbbException(TemplateErrorCodeEnum.API_ERROR_350009);
                }
            }
        } catch (Exception e) {
            LOG.error("BI相关的表单初始化失败",e);
            throw  new XbbException(TemplateErrorCodeEnum.API_ERROR_350009);
        }
        return new ScriptVO();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ScriptVO initCustomerList(AllScriptDTO allScriptDTO) throws XbbException {

        for (String corpid : allScriptDTO.getCorpidList()) {
            PaasAppEntity paasAppEntity = paasAppModel.getByAlias(XbbRefTypeEnum.CRM.getAlias(),  corpid);
            if (paasAppEntity == null) {
                continue;
            }
            PaasMenuEntity paasMenuEntity = paasMenuModel.getByAlias(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getAlias(), paasAppEntity.getId(), corpid);
            if (paasMenuEntity == null) {
                continue;
            }
            List<PaasMenuEntity> menuList = new ArrayList<>();
            menuList.add(paasMenuEntity);
            // 通过分组菜单，得到需要插入的表单列表
            List<FormEntityAddDTO> formList = new ArrayList<>();
            FormAddBatchDTO formAddBatchDTO = new FormAddBatchDTO();
            BeanUtil.copyProperties(allScriptDTO, formAddBatchDTO);
            formAddBatchDTO.setCorpid(corpid);
            initCrmMenuHelp.getFormList(formList, menuList);
            formAddBatchDTO.setFormList(formList);
            FormAddBatchVO formAddBatchVO = paasFormService.addBatch(formAddBatchDTO);
            if (Objects.isNull(formAddBatchVO)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
            }
            MenuInitDTO menuInitDTO = new MenuInitDTO();
            BeanUtil.copyProperties(allScriptDTO, menuInitDTO);
            menuInitDTO.setCorpid(corpid);
            // 插入表单对应的字段解释
            initCrmMenuHelp.formExplainAddBatch(menuInitDTO, formAddBatchVO);
        }
        return new ScriptVO();
    }

    @Override
    public ScriptVO initMenuColor(AllScriptDTO allScriptDTO) throws XbbException {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("appId", allScriptDTO.getAppId());
        param.put("del", DelEnum.NORMAL.getDel());
        List<PaasMenuEntity> paasMenuList = paasMenuModel.list(param);
        if (Objects.isNull(paasMenuList)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001);
        }
        for(PaasMenuEntity paasMenuEntity: paasMenuList) {
            PaasMenuEntity updateMenu = new PaasMenuEntity();
            updateMenu.setId(paasMenuEntity.getId());
            updateMenu.setCorpid(paasMenuEntity.getCorpid());
            updateMenu.setSaasMark(paasMenuEntity.getSaasMark());
            updateMenu.setAppId(paasMenuEntity.getAppId());
            String alias = paasMenuEntity.getAlias();
            CRMMenuEnum crmMenuEnum = CRMMenuEnum.getByAlias(alias);
            JXCMenuEnum jxcMenuEnum = JXCMenuEnum.getByAlias(alias);
            FundManagementMenuEnum fundManagementMenuEnum = FundManagementMenuEnum.getByAlias(alias);
            ProductMenuEnum productEnum = ProductMenuEnum.getByAlias(alias);
            if (Objects.nonNull(crmMenuEnum) && Objects.nonNull(crmMenuEnum.getAccessLinkEnum())) {
                updateMenu.setColor(crmMenuEnum.getAccessLinkEnum().getColor());
                updateMenu.setIcon(crmMenuEnum.getAccessLinkEnum().getIcon());
                paasMenuModel.update(updateMenu);
            } else if (Objects.nonNull(jxcMenuEnum) && Objects.nonNull(jxcMenuEnum.getAccessLinkEnum())) {
                updateMenu.setColor(jxcMenuEnum.getAccessLinkEnum().getColor());
                updateMenu.setIcon(jxcMenuEnum.getAccessLinkEnum().getIcon());
                paasMenuModel.update(updateMenu);
            } else if (Objects.nonNull(fundManagementMenuEnum) && Objects.nonNull(fundManagementMenuEnum.getAccessLinkEnum())) {
                updateMenu.setColor(fundManagementMenuEnum.getAccessLinkEnum().getColor());
                updateMenu.setIcon(fundManagementMenuEnum.getAccessLinkEnum().getIcon());
                paasMenuModel.update(updateMenu);
            }else if (Objects.nonNull(productEnum) && Objects.nonNull(productEnum.getAccessLinkEnum())) {
                updateMenu.setColor(productEnum.getAccessLinkEnum().getColor());
                updateMenu.setIcon(productEnum.getAccessLinkEnum().getIcon());
                paasMenuModel.update(updateMenu);
            }
        }
        return new ScriptVO();
    }

    private void handOut(Integer businessType, ScriptDTO scriptDTO) throws XbbException{
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum){
            case CUSTOMER_MANAGEMENT:
                initCustomer(scriptDTO);
                break;
            case CONTRACT:
                initContract(scriptDTO);
                break;
            case SALES_OPPORTUNITY:
                initOpportunity(scriptDTO);
                break;
            case CONTACT:
                initContact(scriptDTO);
                break;
            case CUSTOMER_COMMUNICATE:
                initCustomerCommunicate(scriptDTO);
                break;
            case SUPPLIER_COMMUNICATE:
                initSupplierCommunicate(scriptDTO);
                break;
            case COMMUNICATE_PLAN:
                initCommunicatePlan(scriptDTO);
                break;
            case WORKREPORT_DAILY:
                initWorkReportDaily(scriptDTO);
                break;
            case WORKREPORT_WEEKLY:
                initWorkReportWeekly(scriptDTO);
                break;
            case WORKREPORT_MONTHLY:
                initWorkReportMonthly(scriptDTO);
                break;
            case PAYMENT:
                initPayment(scriptDTO);
                break;
            case PAY_PLAN:
                initPayPlan(scriptDTO);
                break;
            case INVOICE:
                initInvoice(scriptDTO);
                break;
            case SUPPLIER:
                initSupplier(scriptDTO);
                break;
            case PURCHASE:
                initPurchase(scriptDTO);
                break;
            case RETURNED_PURCHASE:
                initReturnedPurchase(scriptDTO);
                break;
            case SUPPLIER_CONTACT:
                initSupplierContact(scriptDTO);
                break;
            case ASSEMBLE:
                initAssemble(scriptDTO);
                break;
            case INSTOCK:
                initInstock(scriptDTO);
                break;
            case OUTSTOCK:
                initOutstock(scriptDTO);
                break;
            case INVENTORY:
                initInventory(scriptDTO);
                break;
            case TRANSFER:
                initTransfer(scriptDTO);
                break;
            case BOM_BILL:
                initBomBill(scriptDTO);
                break;
            case PRODUCTION_ORDER:
                initProductionOrder(scriptDTO);
                break;
            case PRODUCT:
                initProduct(scriptDTO);
                break;
            case WAREHOUSE:
                initWarehouse(scriptDTO);
                break;
            case PAYMENT_SHEET:
                initPaymentSheet(scriptDTO);
                break;
            case PAY_SHEET:
                initPayPlanSheet(scriptDTO);
                break;
            case WORK_ORDER:
                initWorkOrder(scriptDTO);
                break;
            case STOCK_PRODUCT:
                initStockProduct(scriptDTO);
                break;
            case BAD_DEBT:
                initBadDebt(scriptDTO);
                break;
            case RED_PAYMENT_SHEET:
                initRedPaymentSheet(scriptDTO);
                break;
            case PUSH_NOTIFY:
                initPushNotify(scriptDTO);
                break;
            case REFUND:
                initRefund(scriptDTO);
                break;
            case CLUE:
                initClue(scriptDTO);
                break;
            default:
                break;
        }
    }

    @Override
    public ScriptVO initForm(AllScriptDTO allScriptDTO) throws XbbException {
        List<Integer> businessTypeList = allScriptDTO.getBusinessTypeList();
        List<String> corpidList = allScriptDTO.getCorpidList();
        try {
            for (String corpid : corpidList) {
                Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                param.put("businessTypeList", businessTypeList);
                param.put("corpid", corpid);
                List<PaasFormEntityExt> formEntitys = paasFormModel.getByBusinessTypes(param);
                if (!formEntitys.isEmpty()) {
                    for (PaasFormEntityExt paasFormEntity : formEntitys) {
                        paasFormEntity.setSummary(JSONObject.toJSONString(initProductMenuHelp.getAppDefaultSummary(paasFormEntity.getBusinessType())));
                        paasFormEntity.setCustomTitle(JSONObject.toJSONString(initProductMenuHelp.getAppDefaultTitle(paasFormEntity.getBusinessType())));
                        paasFormEntity.setLabels(JSONObject.toJSONString(initProductMenuHelp.getAppDefaultLabel(paasFormEntity.getBusinessType())));
                    }
                    paasFormModel.initBatch(formEntitys, corpid);
                }
            }
        } catch (Exception e) {
            LOG.error("initForm 出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return null;
    }

    @Override
    public ScriptVO initWorkOrderForm(AllScriptDTO allScriptDTO) throws XbbException {
        List<String> corpidList = allScriptDTO.getCorpidList();
        try {
            Integer businessType = XbbRefTypeEnum.WORK_ORDER.getCode();
            for (String corpid : corpidList) {
                Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                param.put("corpid", corpid);
                List<WorkOrderFormEntity> formEntitys = workOrderFormModel.findEntitys(param);
                if (!formEntitys.isEmpty()) {
                    for (WorkOrderFormEntity paasFormEntity : formEntitys) {
                        paasFormEntity.setSummary(JSONObject.toJSONString(initWorkOrderHelp.getWorkOrderDefaultSummary(businessType)));
                        paasFormEntity.setCustomTitle(JSONObject.toJSONString(initWorkOrderHelp.getWorkOrderDefaultTitle(businessType)));
                        paasFormEntity.setLabels(JSONObject.toJSONString(initWorkOrderHelp.getWorkOrderDefaultLabel(businessType)));
                    }
                    workOrderFormModel.initBatch(formEntitys, corpid);
                }
            }
        } catch (Exception e) {
            LOG.error("initWorkOrderForm 出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return null;
    }
    @Override
    public ScriptVO initMarketActivity(ScriptDTO scriptDTO) throws XbbException {
        List<TempMarketActivityEnum> allEnum = TempMarketActivityEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempMarketActivityEnum tempMarketActivityEnum : allEnum) {
            MarketActivityEnum anEnum = tempMarketActivityEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<MarketActivityEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempMarketActivityEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(tempMarketActivityEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(tempMarketActivityEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.MARKET_ACTIVITY.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initMarketActivity=================================");
        return scriptVO;
    }



    @Override
    public ScriptVO initMarketingActivityManagement(ScriptDTO scriptDTO) throws XbbException {
        List<TempMarketingActivityManagementEnum> allEnum = TempMarketingActivityManagementEnum.getAllEnum();
        if (allEnum.isEmpty()) {
            LOG.error("优惠券活动管理模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempMarketingActivityManagementEnum activityManagementEnum : allEnum) {
            MarketingActivityManagementEnum anEnum = activityManagementEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<MarketingActivityManagementEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (enumAttrs == null) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempMarketingActivityManagementEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(activityManagementEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001.getCode(), SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }
                fieldAttrEntity.setDefaultName(activityManagementEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        FormExplainAddDTO formExplainAddDTO = new FormExplainAddDTO();
        BeanUtil.copyProperties(scriptDTO, formExplainAddDTO);
        formExplainAddDTO.setFormId(10000L);
        formExplainAddDTO.setAppId(10000L);
        formExplainAddDTO.setMenuId(10000L);

        formExplainAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
        formExplainAddDTO.setBusinessType(9003);
        formExplainAddDTO.setFormList(fieldAttrEntityList);
        FormExplainAddVO formExplainAddVO = paasFormExplainService.add(formExplainAddDTO);
        LOG.info("=========================模板数据刷成功了initWarehouseOriStock=================================");
        return null;
    }

    @Override
    public ScriptVO initCompetitor(ScriptDTO scriptDTO) throws XbbException {
        List<TempCompetitorEnum> allEnum = TempCompetitorEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempCompetitorEnum tempCompetitorEnum : allEnum) {
            CompetitorEnum anEnum = tempCompetitorEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<CompetitorEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempCompetitorEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(tempCompetitorEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(tempCompetitorEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.COMPETITOR.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initCompetitor=================================");
        return scriptVO;
    }

    @Override
    public ScriptVO initCompetitorAnalysis(ScriptDTO scriptDTO) throws XbbException {
        List<TempCompetitorAnalysisEnum> allEnum = TempCompetitorAnalysisEnum.getAllEnum();
        if (Objects.equals(allEnum, null)) {
            LOG.error("业务模板初始化没有对应枚举");
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        List<FieldAttrEntity> fieldAttrEntityList = new ArrayList<>();
        List<String> enumAttrs = null;
        for (TempCompetitorAnalysisEnum tempCompetitorAnalysisEnum : allEnum) {
            CompetitorAnalysisEnum anEnum = tempCompetitorAnalysisEnum.getAnEnum();
            // 包装业务枚举类
            EnumBase<CompetitorAnalysisEnum> enumBase = new EnumBase<>(anEnum);
            Class<?> clazz = enumBase.t.getClass();
            if (Objects.equals(enumAttrs, null)) {
                // 获取业务枚举类中的属性，以集合的形式返回，同一个枚举的属性值只获取一次
                enumAttrs = InitExplainsHelper.getBusinessEnumAttrs(clazz);
            }
            // 初始化字段解释
            FieldAttrEntity fieldAttrEntity = InitExplainsHelper.setField(enumBase, enumAttrs);
            if (fieldAttrEntity != null) {
                String saasAttr = fieldAttrEntity.getSaasAttr();
                String attr = saasAttr.substring(0, 1).toUpperCase() + saasAttr.substring(1);
                String methodName = "init" + attr;
                try {
                    commonFiledInit(fieldAttrEntity);
                    Method method = TempCompetitorAnalysisEnum.class.getMethod(methodName, FieldAttrEntity.class);
                    method.invoke(tempCompetitorAnalysisEnum, fieldAttrEntity);
                } catch (NoSuchMethodException e) {
                    // 没有对应字段的初始化方法
                } catch (Exception e) {
                    LOG.error(e.getMessage());
                }
                fieldAttrEntity.setDefaultName(tempCompetitorAnalysisEnum.getAnEnum().getAttrName());
                fieldAttrEntityList.add(fieldAttrEntity);
            }
        }
        ScriptVO scriptVO = insertFormExplain(scriptDTO, XbbRefTypeEnum.COMPETITOR_ANALYSIS.getCode(), fieldAttrEntityList);
        LOG.info("=========================模板数据刷成功了initCompetitor=================================");
        return scriptVO;
    }
}

